package com.liaoban.app.ui.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.liaoban.app.R;
import com.liaoban.app.api.type.request.EarnDetailRequest;
import com.liaoban.app.biz.CommonBiz;
import com.liaoban.app.constants.ExtraParam;
import com.liaoban.app.helper.ImageHelper;
import com.liaoban.app.ui.base.BaseToolbarActivity;
import com.liaoban.app.util.CommonUtils;
import com.liaoban.app.util.DateTimeUtils;

import butterknife.BindInt;
import butterknife.BindView;

/**
 * Created by ybc on 2018/7/13 0013.
 * 我的收益详情
 */
public class EarnDetailActivity extends BaseToolbarActivity {
    @BindView(R.id.iv_src)
    ImageView ivSrc;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_id)
    TextView tvId;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_description)
    TextView tvDesc;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_deal_indent)
    TextView tvDealIndent;

    private String mId;
    private String mType;

    public static Intent newIntent(Context context, String id, String type) {
        Intent intent = new Intent(context, EarnDetailActivity.class);
        intent.putExtra(ExtraParam.ID, id);
        intent.putExtra(ExtraParam.TYPE, type);
        return intent;
    }

    @Override
    protected String getNewTitle() {
        return "账单详情";
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_earn_detail;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        initData();
        showRunningDialog();
        loadData();
    }

    private void initData() {
        mId = getIntent().getStringExtra(ExtraParam.ID);
        mType = getIntent().getStringExtra(ExtraParam.TYPE);
    }

    private void loadData() {
        EarnDetailRequest earnDetailRequest = new EarnDetailRequest();
        earnDetailRequest.setId(mId);
        earnDetailRequest.setType(mType);
        startTask(CommonBiz.getInstance().userMoneyDetails(earnDetailRequest), earnBaseResponse -> {
            ImageHelper.load(ivSrc, earnBaseResponse.data.getWuser_src());
            tvName.setText(earnBaseResponse.data.getWuser_name());
            tvId.setText("ID:" + earnBaseResponse.data.getWuser_id());
            tvMoney.setText(earnBaseResponse.data.getMoney());
            tvDesc.setText(earnBaseResponse.data.getDescription());
            tvTime.setText(DateTimeUtils.formatData(earnBaseResponse.data.getTime() * 1000, "yyyy-MM-dd HH:mm:ss"));
            tvDealIndent.setText(earnBaseResponse.data.getDeal_indent());
        });
    }
}
